<template>
  <Table border :columns="columns1" :data="data1" :loading="loading"></Table>
</template>
<script>
import cover2Api from '@/api/cover2'
export default {
  data() {
    return {
      loading: false,
      columns1: [
        {
          title: '季度',
          key: 'title',
          width: 120
        },
        {
          title: '数字化应用覆盖深度',
          key: 'depth',
          width: 160
        },
        {
          title: '数字化应用覆盖广度',
          key: 'scope',
          width: 160
        },
        {
          title: '关键业务环节数字化覆盖度',
          key: 'keyLink'
        }
      ],
      data1: []
    }
  },
  props: {
    buCode: {
      type: String,
      default: ''
    },
    dcPeriod: {
      type: String,
      default: ''
    }
  },
  created() {
    this.$emit('SetTitle', '覆盖度')
    this.$emit('SetPageWidth', 700)
    this.$emit('SetPageActions', [
      {
        text: '知道了',
        theme: 'primary',
        handle: () => this.$emit('Close')
      }
    ])
    this.loading = true
    cover2Api
      .currentCompute({ buCode: this.buCode, dcPeriod: this.dcPeriod })
      .then(res => {
        this.loading = false
        if (res.data.code === 200) {
          const { depth, keyLink, scope, previousDepth, previousKeyLink, previousScope } = res.data.data
          this.data1 = [
            {
              title: '上季度',
              depth: (previousDepth * 100).toFixed(2) + '%',
              scope: (previousScope * 100).toFixed(2) + '%',
              keyLink: (previousKeyLink * 100).toFixed(2) + '%'
            },
            {
              title: '测算当前季度',
              depth: (depth * 100).toFixed(2) + '%',
              scope: (scope * 100).toFixed(2) + '%',
              keyLink: (keyLink * 100).toFixed(2) + '%'
            }
          ]
        }
      })
      .catch(e => {
        this.loading = false
      })
  }
}
</script>
